﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TurtleLib.ComputerCraft;

namespace TurtleLib.Simulation
{
  public struct AdvancedComputerScriptEnvironment
  {
    public Term term;
    public PeripheralUtility peripheral;
    public ComputerCraft.OperatingSystem os;
  }

  public delegate void AdvancedComputerScript(AdvancedComputerScriptEnvironment environment);
}

namespace TurtleLib.ComputerCraft
{
  public partial class AdvancedComputer : Computer
  {
    internal class AdvancedComputerAccess
    {
      private AdvancedComputer _computer;

      public AdvancedComputerAccess(AdvancedComputer computer)
      {
        _computer = computer;
      }

      public void SetBootScript(TurtleLib.Simulation.AdvancedComputerScript script)
      {
        TurtleLib.Simulation.AdvancedComputerScriptEnvironment environment;
        environment.term = Term;
        environment.peripheral = PeripheralUtility;
        environment.os = OS;

        var osaccess = new OperatingSystem.OperatingSystemAccess(OS);
        osaccess.SetBoot(() => script(environment));
      }

      public Term Term { get { return _computer._term; } }
      public PeripheralUtility PeripheralUtility { get { return _computer._peripheral; } }
      public OperatingSystem OS { get { return _computer._os; } }
    }
  }
}
